#!/usr/bin/python
# -*- coding: utf-8 -*-
"""docstrings
"""


import unittest
from uuid import uuid1, uuid4
import base64
import urllib2

class ContactKeys(object):
    PRIMARY_ID = 'primary_id'
    USERNAME = 'username'
    MOBILE = 'mobile'
    TELEPHONE = 'telephone'
from contact.common import json

class ViewsTest(unittest.TestCase):
    
    def request(self, urlpath, data=None):
        url = 'http://127.0.0.1:8080%s' % urlpath
        r = urllib2.urlopen(url, data)
        r.content = r.read()
        r.status_code = r.code
        return r
    
    def test_get_contact(self):
        response = self.request('/info/contact/get?user=mk2')
        self.assertEqual(response.status_code, 200)
        for c in json.loads(response.content):
            print c
        
    def test_save_contact(self):
        contacts = [
            {ContactKeys.PRIMARY_ID: '1',
             ContactKeys.USERNAME: '袁锋',
             ContactKeys.MOBILE: '13760792910',
             ContactKeys.TELEPHONE: '82610658'},
            {ContactKeys.PRIMARY_ID: '13',
             ContactKeys.USERNAME: '袁锋2',
             ContactKeys.MOBILE: '13760792910',
             ContactKeys.TELEPHONE: '82610658'},
            {ContactKeys.PRIMARY_ID: '11',
             ContactKeys.USERNAME: 'mk2',
             ContactKeys.MOBILE: '13760792910',
             ContactKeys.TELEPHONE: '82610658'},
        ]
        data = 'ENCODE_DATAS=' + base64.b64encode(json.dumps(contacts))
        response = self.request('/info/contact/save?user=mk2', data)
        print response.content
        
if __name__ == '__main__':
    unittest.main()